#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class Solution {
public:
    vector<vector<int>> fourSum(vector<int>& nums, int target) {
        vector<vector<int>> ret;
        int len = nums.size();
        if (len < 4) return ret;
        sort(nums.begin(), nums.end());
        long long first = INT_MIN;
        for (int i = 0; i < len; i++) {
            while (i < len && first == nums[i])
                i++;
            if (i >= len) break;
            first = nums[i];
            long long second = INT_MIN;
            for (int j = i + 1; j < len; j++) {
                while (j < len && second == nums[j])
                    j++;
                if (j >= len) break;
                second = nums[j];
                int left = j + 1, right = len - 1;
                while (left < right) {
                    long long sum = first + second + nums[left] + nums[right];
                    if (sum < (long long)target) {
                        left++;
                    }
                    else if (sum > (long long)target) {
                        right--;
                    }
                    else {
                        ret.push_back({ (int)first, (int)second, nums[left], nums[right] });
                        int leftnum = nums[left], rightnum = nums[right];
                        left++, right--;
                        while (left < right && nums[left] == leftnum)
                            left++;
                        while (left < right && nums[right] == rightnum)
                            right--;
                    }
                }
            }
        }
        return ret;
    }
};

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int maxlen = INT_MAX;
        int left = 0, right = 0, sum = 0;
        int len = nums.size();
        bool flag = true;
        while (right < len) {
            sum += nums[right];
            while (sum >= target) {
                flag = false;
                maxlen = min(maxlen, right - left + 1);
                sum -= nums[left++];
            }
            right++;
        }
        if (flag) return 0;
        return maxlen;
    }
};
int main() {
    Solution s;
    vector<int> v({ 0,0,0,0 });
    s.fourSum(v,0);

    return 0;
}